import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        int Max1 = Integer.MIN_VALUE;
        for (int i = 0; i < n - 1; i++) {
            Max1 = Math.max(Max1,arr[i] * arr[i+1]);
        }

        for (int i = 0; i < n - 1; i++) {
            int left = arr[i];
            int right = arr[i+1];

            arr[i] = right;
            arr[i+1]  = left;

            //处理边界情况 数据越界问题
            if(i > 0){
                Max1 = Math.max(Max1,arr[i-1]*arr[i]);
            }
            Max1 = Math.max(Max1,arr[i]*arr[i+1]);
            if(i+2 < n){
                Max1 = Math.max(Max1,arr[i+1]*arr[i+2]);
            }

            arr[i] = left;
            arr[i+1] = right;
        }
        System.out.println(Max1);
    }

    private static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}
